<%--
  Created by IntelliJ IDEA.
  User: zhangDongFei
  Date: 2020/11/26
  Time: 21:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" charset="GBK">
    <script src="${pageContext.request.contextPath}/jquery-3.5.1.min.js" charset="GBK"></script>
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <link href="${pageContext.request.contextPath}/toastr-master/toastr.min.css" rel="stylesheet"/>
    <script src="${pageContext.request.contextPath}/toastr-master/toastr.min.js" charset="GBK"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<div class="layui-card">
    <div class="layui-card-header">修改密码</div>
    <div class="layui-card-body">
        <form class="layui-form" id="updateForm">
            <input type="text" style="display: none" name="id" value="${sessionScope.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="oldPassword" required lay-verify="required|oldPassword" placeholder="请输入旧密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="pwd" id="newPassword" required lay-verify="required|newPassword1|newPassword" placeholder="请输入新密码"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到12个字符</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="pwd" required lay-verify="required|newPassword2" placeholder="请确认新密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="reset" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //修改自己密码表单验证和提交
        var staffPassword = ${sessionScope.pwd};
        form.verify({
            oldPassword: function (value) { //value：表单的值、item：表单的DOM对象
                if (staffPassword != value) {
                    return '旧密码不正确';
                }
            }
            ,newPassword1: function (value) { //value：表单的值、item：表单的DOM对象
                if (staffPassword == value) {
                    return '不能和更改前密码一致';
                }
            }
            , newPassword: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , newPassword2: function (value, item) { //value：表单的值、item：表单的DOM对象
                if ($("#newPassword").val() != value) {
                    return '两次输入密码不一致';
                }
            }
        });
        //监听提交
        form.on('submit(formDemo)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: '${pageContext.request.contextPath}/YG/updM',
                type: 'post',
                async: false,
                data: data.field,
                success: function (result) {
                    if (result != 0) {
                        $("#updateForm")[0].reset();
                       layer.msg("修改成功");
                    } else {
                        layer.msg("修改失败");
                    }
                },
            });
            return false;
        });
    });
</script>
</html>
